package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo7 {
    public static void main(String[] args) {
        //1年级1班共有多少个人
        /*
        SELECT COUNT(*) count
        FROM student s
        JOIN class c ON c.id=s.class_id
        WHERE c.name='1年级1班';
         */

        try (Connection conn= DBUtil.getConnection();)
        {
            Statement state = conn.createStatement();
            String s= "SELECT COUNT(*) count\n" +
                    "        FROM student s\n" +
                    "        JOIN class c ON c.id=s.class_id\n" +
                    "        WHERE c.name='1年级1班';";
            ResultSet r= state.executeQuery(s);
            while(r.next()){
                int count = r.getInt("count");
                System.out.println("1年级1班共有"+count+"人");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
